/**
 * ****************************************************************************
 * Project: RoboBridge
 * ----------------------------------------------------------------------------
 * -------------------------- [c]2012 - KrawallMann ---------------------------
 * ---------------------- http://www.krawallmann.de.tc/ -----------------------
 * ****************************************************************************
 * File: LANLocalDevice.java Package: tc.de.krawallmann.robobridge.communication
 * Version: 1.0 Author(s): KrawallMann
 * ****************************************************************************
 * Description:
 * ****************************************************************************
 */
package tc.de.krawallmann.robobridge.communication.lan;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;

import tc.de.krawallmann.robobridge.communication.AbstractLocalCommunicationDevice;
import tc.de.krawallmann.robobridge.communication.CommunicationDeviceType;

/**
 * The Class LANLocalDevice represents a locally installed LAN adaptor.
 * 
 * @author KrawallMann
 * @version 1.0
 */
public class LANLocalDevice extends AbstractLocalCommunicationDevice {

	/** The address. */
	private transient final InetAddress address;

	/**
	 * Instantiates a new LAN local device.
	 * 
	 * @throws UnknownHostException
	 *             the unknown host exception
	 */
	public LANLocalDevice() throws UnknownHostException {
		super();
		address = InetAddress.getLocalHost();
	}

	/*
	 * (non-Javadoc)
	 * @see communication.AbstractLocalCommunicationDevice#getAdapterName()
	 */
	@Override
	public String getAdapterName() {
		try {
			return NetworkInterface.getByInetAddress(address).getDisplayName();
		} catch (final SocketException e) {
			return "N/A";
		}
	}

	/*
	 * (non-Javadoc)
	 * @see communication.CommunicationDevice#getAddress()
	 */
	@Override
	public String getAddress() {
		return address.getHostAddress();
	}

	/*
	 * (non-Javadoc)
	 * @see communication.CommunicationDevice#getDeviceType()
	 */
	@Override
	public CommunicationDeviceType getDeviceType() {
		return CommunicationDeviceType.LAN_DEVICE;
	}

	/*
	 * (non-Javadoc)
	 * @see communication.CommunicationDevice#getName()
	 */
	@Override
	public String getName() {
		return address.getHostName();
	}
}
